package com.leyou.item.web;


import com.leyou.item.pojo.*;
import com.leyou.item.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author:yanjizhw@163.com
 * @date:2019-10-14 13:11
 * 描述:
 * @since:1.0.0
 */
@Controller
@RequestMapping("role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @ResponseBody
    @RequestMapping("tree")
    public ResponseEntity<List<Acl>> roleTree(){

        return ResponseEntity.ok(roleService.roleTree());
    }

    @ResponseBody
    @RequestMapping("list")
    public ResponseEntity<List<Role>> roleList(){
        return ResponseEntity.ok(roleService.roleList());
    }

    @ResponseBody
    @RequestMapping("getAcl")
    public ResponseEntity<List<Acl>> getAcl(RoleAcl roleAcl){

        return ResponseEntity.ok(roleService.getAcl(roleAcl));
    }

    @RequestMapping("addRoleAcl")
    public String addRoleAcl(RoleAcl roleAcl, String[] ids){

        roleService.addRoleAcl(roleAcl, ids);
        return "role";
    }

    @ResponseBody
    @RequestMapping("getUser")
    public ResponseEntity<List<Manager>> getUser(RoleUser roleUser){

        return ResponseEntity.ok(roleService.getUser(roleUser));
    }

    @ResponseBody
    @RequestMapping("userTree")
    public ResponseEntity<List<Manager>> userTree(){

        return ResponseEntity.ok(roleService.userTree());
    }

    @RequestMapping("addRoleUser")
    public String addRoleUser(RoleAcl roleAcl, String[] ids){

        roleService.addRoleUser(roleAcl, ids);

        return "role";
    }
}
